class Solution {
    int n;
    bool vis[210] = { 0 };
    int ans = 0;
public:
    void dfs(vector<vector<int> >& m, int x)
    {
        vis[x] = true;

        for (int i = 0; i < n; i++)
        {
            if (!vis[i] && m[x][i] == 1)
            {
                dfs(m, i);
            }
        }
    }

    int citys(vector<vector<int> >& m) {
        n = m.size();
        for (int i = 0; i < n; i++)
        {
            if (!vis[i])
            {
                ans++;
                dfs(m, i);
            }
        }

        return ans;
    }
};
